(in-package #:experiment)

(defvar *warnings* nil
  "The list of warnings accumulated")

(defmacro record-warnings (&body body)
  `(handler-bind
       ((warning (lambda (c)
                   (setf *warnings* (append *warnings* (list c)))
                   (continue))))
     ,@body))

(defclass warnings (state)
  ())

(defmethod state-init (exp (state warnings))
  (lg 'start :warnings *warnings*)
  (if *warnings*
      (setf (gwee:view-subviews state)
            (list (make-instance 'gwee:text-area
                                 :width :maximum
                                 :height :maximum
                                 :vertical-justification :center
                                 :horizontal-justification :center
                                 :data *warnings*))
            *warnings* nil)
      (state-onward exp state)))

(define-action onward ((state warnings)
                       (keypress :char #\Space))
  (state-onward *experiment* state))
